home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 09 - 1993 / 09.09 Sep 93 / FrameAnim App ƒ / VBlank.c < prev   
Encoding:
Text File  |  1994-11-06  |  3.1 KB  |  111 lines  |  [TEXT/KAHL]

  1. // ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  2. // • Program:    FrameAnim
  3. // • File:        VBlank.c
  4. // •
  5. // • Copyright © 1993 by Scott B. Steinman, O.D., Ph.D. All Rights Reserved.
  6. // ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  7.  
  8. #include "FrameAnim.h"
  9.  
  10. // • ------------------ External Globals ---------------------------------- 
  11.  
  12. extern CWindowPtr        gMainWindow;    // • From Main.c file    
  13. extern GWorldPtr        gFrames[];        // • From Main.c file
  14. extern GDHandle            gDevice;        // • From Main.c file
  15. extern Settings            gSettings;        // • From Main.c file
  16.                         
  17. // • ------------------ Globals ------------------------------------------- 
  18.  
  19. XVBLTask                gXVBLTask;
  20.  
  21. // •------------------- Static Variables ----------------------------------
  22.  
  23. static short            sSlotNum;
  24. static OSErr            sErr;
  25.                     
  26. // • ------------------ Set Up VBlank Interrupt Timing Task --------------- 
  27.  
  28. void
  29. SetUpVBlankAnimation( void )
  30. // •
  31. // • Initiates VBlank interrupt task to time transfer of GWorlds to screen.
  32.  
  33. {
  34.     AuxDCEHandle    devCtl = NullHandle;
  35.  
  36.     HLock( (Handle) gDevice );
  37.     devCtl = (AuxDCEHandle) GetDCtlEntry( (**gDevice).gdRefNum );
  38.     HLock( (Handle) devCtl );
  39.     sSlotNum = (**devCtl).dCtlSlot;
  40.     HUnlock( (Handle) devCtl );
  41.     HUnlock( (Handle) gDevice );
  42.     
  43.     gXVBLTask.vbl.vblAddr = (ProcPtr) VideoProc;
  44.     gXVBLTask.vbl.qType = vType;    
  45.     gXVBLTask.vbl.vblCount = 0;            // • Initially disable VBlank task
  46.     gXVBLTask.vbl.vblPhase = 0;
  47.     gXVBLTask.a5 = SetCurrentA5();        // • Get program's current A5
  48.                 
  49.     gXVBLTask.frames = gSettings.numFrames;    
  50.     gXVBLTask.frameDelay = gSettings.frameDelay;    
  51.     gXVBLTask.frameIndex = -1;                // • Will be set to 0 on first VBlank
  52.     gXVBLTask.showFrame = false;            // • Disable showing frame
  53.  
  54.     if (sSlotNum >= 0)
  55.         sErr = SlotVInstall( (QElemPtr) &gXVBLTask, sSlotNum );
  56.     else 
  57.         sErr = VInstall( (QElemPtr) &gXVBLTask );
  58. }
  59.  
  60. // • ------------------ Remove VBlank Interrupt Timing Task --------------- 
  61.  
  62. void
  63. ShutDownVBlankAnimation( void )
  64. // •
  65. // • Removes our vertical blank task from interrupt queue.
  66. {
  67.     gXVBLTask.frameIndex = -1;
  68.     gXVBLTask.vbl.vblCount = 0;        
  69.     
  70.     if (gXVBLTask.vbl.vblAddr != (ProcPtr) VideoProc )
  71.         return;
  72.     if (sSlotNum >= 0)
  73.         sErr = SlotVRemove( (QElemPtr) &gXVBLTask, sSlotNum );
  74.     else 
  75.         sErr = VRemove( (QElemPtr) &gXVBLTask );
  76. }
  77.  
  78. // • ------------------ Increment Frame Number (VBlank Task Routine) ------ 
  79.  
  80. #pragma options(assign_registers,redundant_loads)
  81.  
  82. void
  83. VideoProc( void )
  84. // •
  85. // • Increment frame number of pre-recorded animation
  86. // • sequence in sync with vertical blank interrupt.
  87. {
  88.     long            currA5;
  89.     XVBLTaskPtr     theVBLTask;
  90.     
  91.     // • Get our task record from A0 register
  92.     
  93.     theVBLTask = (XVBLTaskPtr) GetVBLRec();
  94.     
  95.     currA5 = SetA5( theVBLTask->a5 );
  96.     
  97.     if (theVBLTask->frameIndex < theVBLTask->frames) {
  98.         theVBLTask->frameIndex++;        // • Set next frame number 
  99.         theVBLTask->showFrame = true;    // • Show this frame 
  100.  
  101.         // • Reset VBL countdown 
  102.         theVBLTask->vbl.vblCount = theVBLTask->frameDelay;    
  103.     }
  104.     else {
  105.         theVBLTask->showFrame = false;    // • Don't display frame    
  106.         theVBLTask->vbl.vblCount = 0;    // • Inhibit VBL task 
  107.     }
  108.  
  109.     currA5 = SetA5( currA5 );
  110. }
  111.